// Gamemode

Assault.Gamemode        = {}
Assault.Gamemode.List   = {}
Assault.Gamemode.Active = false

// New

function Assault.Gamemode:New(ID)
	local Table = {}
	
	// Meta table
	
	setmetatable(Table, self)
	
	// Index
	
	self.__index = self
	
	// ID
	
	Table.ID = ID
	
	// Return table
	
	return Table
end

// Load

function Assault.Gamemode.Load(ID)
	if (Assault.Gamemode.List[ID]) then
		Assault.Gamemode.Active = table.Copy(Assault.Gamemode.List[ID])
		
		// Gamemode run hook
		
		Assault.Gamemode.Active:GamemodeRunHook("OnGamemodeLoad")
		
		// Return true
		
		return true
	else
		return false
	end
end

// Unload

function Assault.Gamemode.Unload(ID)
	if (Assault.Gamemode.Active) then
		Assault.Gamemode.Active:GamemodeRunHook("OnGamemodeUnload")
		
		// Destroy level
		
		Assault.Level.Destroy()
		
		// Gamemode active false
		
		Assault.Gamemode.Active = false
		
		// Return true
		
		return true
	else
		return false
	end
end

//Gamemode run hook

function Assault.Gamemode:GamemodeRunHook(ID, ...)
	if (self[ID]) then
		self[ID](self, unpack(arg))
	end
end

// Create

function Assault.Gamemode:Create()
	Assault.Gamemode.List[self.ID] = self
end

// Load gamemodes

local Files = file.FindInLua("Assault/Gamemodes/*")

// Loop

for K, V in pairs(Files) do
	local Directory = file.IsDir("../lua/Assault/Gamemodes/"..V.."/")
	
	// Check directory
	
	if (Directory) then
		if (V != ".." and V != ".") then
			local Gamemodes = file.FindInLua("Assault/Gamemodes/"..V.."/*.lua")
			
			// Loop
			
			for B, J in pairs(Gamemodes) do
				include("Assault/Gamemodes/"..V.."/"..J)
			end
		end
	end
end